package cn.kai.base;

import cn.hutool.core.collection.CollUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 Author: cKnight
 Date: 2025/2/14
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TreeNode<T extends TreeNode> {
    private Long id;
    private String name;
    private Long parentId;
    private Boolean disabled=false;
    private List<T> children = new ArrayList<>();
    private Integer sort;

    public void addChildren(T treeNode) {
        children.add(treeNode);
    }

    public void addChildrenList(List treeNodes) {
        if (!CollUtil.isEmpty(treeNodes)){
            if (CollUtil.isEmpty(children)){
                children = new ArrayList<>();
            }
            children.addAll(treeNodes);
        }else {
            children = CollUtil.newArrayList();
        }
    }

    public List<T> getChildren() {
        if(children.size() <= 0){
            return null;
        }
        return children;
    }
}
